﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Chinesys.Domain;
using Chinesys.Entities;

namespace Chinesys.UI.Helpers
{
    public static class SecurityHelper
    {
        public static UserEntity GetLoggedUser(string username)
        {
            if (string.IsNullOrWhiteSpace(username))
                return null;

            return UserDomain.GetByName(username);
        }

        public static UserEntity GetLoggedCustomer(int userID)
        {
            return UserDomain.GetByUserID(userID);
        }

        public static UserEntity GetByNameAndPass(string username, string password)
        {
            return UserDomain.GetByNameAndPass(username, password);
        }

        public static bool LogOnUser(string username, string password, out string role)
        {
            UserEntity user = GetByNameAndPass(username, password);

            if (user != null)
            {
                role = user.Role.RoleName;
                return true;
            }
            else
            {
                role = null;
                return false;
            }
        }                

    }
}